home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 6 / demos / sieve.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-11-19  |  1.6 KB  |  67 lines

  1.  /* This is a coding of the SIEVE program
  2.  benchmark published in BYTE, Nov. 1985.
  3.  It has been changed slightly so it can
  4.  use the 200hz clock on the 520ST
  5.  Both the int and register code is
  6.  included just comment out one or the other.
  7.  The execution times were 4.15 seconds
  8.  for the int. version and 2.45 for the register.
  9.  Not to brag on the 520 but these are
  10.  really good times. The best I've seen. */
  11.  
  12.  
  13. #include "stdio.h"
  14. #include "define.h" /* this is true, false definition */
  15. #include "osbind.h" /* gemdos */
  16.  
  17.  
  18. #define SIZE 8190
  19. LONG save_ssp;
  20.  
  21.  
  22. char flags[SIZE + 1] = {0};
  23.  
  24.  
  25. main()
  26. {
  27.      /* register i, prime, k, count, iter; */
  28.      int i, prime, k, count, iter;
  29.      UWORD ticks, *hz_200;
  30.      
  31.  
  32.      hz_200 = 0x4bc;
  33.      save_ssp = Super(0L);
  34.      
  35.  
  36.      puts("\n\n\n\n\nPress any key to begin test...");
  37.      getchar();
  38.      puts("\nStarting\n");
  39.      ticks = *hz_200;
  40.      
  41.  
  42.      for(iter = 1; iter <= 10; iter++) {
  43.           count = 0;
  44.           for(i = 0; i <= SIZE; i++)
  45.                flags[i] = TRUE;
  46.           for(i = 0; i <= SIZE; i++) {
  47.                if (flags[i]) {
  48.                     prime = i+i+3;
  49.                     for (k = i+prime; k <= SIZE; k+=prime)
  50.                          flags[k] = FALSE;
  51.                     count++;
  52.                }
  53.           }
  54.      }
  55.      
  56.  
  57.      ticks = *hz_200 - ticks;
  58.      printf("ticks = %d\n",ticks);
  59.      printf("Time = %f seconds\n",ticks * .005);
  60.      printf("Primes = %d\n",count);
  61.      printf("Done, press any key to continue...\n");
  62.      getchar();
  63.      Super(save_ssp);
  64.      
  65.  
  66. }
  67. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə